package com.lam.common.components.easyexcel.handlers;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;

/**
 * 冻结行和列的Sheet
 * @author lam
 *
 */
public class FreezeSheetWriteHandler implements SheetWriteHandler{
	
	private int colSplit;
	private int rowSplit;
	
	private int leftmostColumn;
	private int topRow;
	
	public FreezeSheetWriteHandler(int rowSplit, int colSplit) {
		this.rowSplit = rowSplit;
		this.colSplit = colSplit;
	}
	
	public FreezeSheetWriteHandler(int rowSplit) {
		this.rowSplit = rowSplit;
	}
	
	@Override
	public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {}

	@Override
	public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
		
		if(colSplit == 0){
			leftmostColumn = 0;
		}else if(leftmostColumn == 0){
			leftmostColumn = colSplit+1;
		}
		
		if(rowSplit == 0){
			topRow = 0;
		}else if(topRow == 0){
			topRow = rowSplit+1;
		}
		
		writeSheetHolder.getSheet().createFreezePane(colSplit, rowSplit, leftmostColumn, topRow);
	}
}
